package ru.aslanov.schedule.server.services;

import ru.aslanov.schedule.model.Entity;
import ru.aslanov.schedule.model.Operation;
import ru.aslanov.schedule.model.Schedule;
import ru.aslanov.schedule.server.AccessDeniedException;
import ru.aslanov.schedule.server.AccessManager;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by IntelliJ IDEA.
 * Created: Feb 9, 2010 4:57:10 PM
 *
 * @author Sergey Aslanov
 */
public abstract class ScheduleChildService<Child extends Entity> extends ParentChildService<Child, Schedule>{
    protected ScheduleChildService(String orderBy) {
        super("schedule", "schedule", orderBy);
    }


    @Override
    protected String getDefaultInputLang(HttpServletRequest request) {
        return getParent(getPersistanceManager(), request).getDefaultInputLanguage();
    }

    @Override
    protected Class<Schedule> getParentClass() {
        return Schedule.class;
    }

    @Override
    protected void checkParentViewAccess(String parentKey, HttpServletRequest request) throws AccessDeniedException {
        AccessManager am = AccessManager.getInstance();
        if (!am.hasAccessToSchedule(parentKey, Operation.VIEW)) {
            throw new AccessDeniedException(request);
        }

    }

}
